package com.hailin.lease.web.app.service.Impl;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.Client;
import com.hailin.lease.web.app.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: yuhailin
 * @description
 * @date: 2024/8/5 17:08
 */

@Service
public class SmsServiceImpl implements SmsService {
    @Autowired
    private Client client;
    /**
     * 发送短信
     * @param phone
     * @param verifyCode
     */
    public void sendCode(String phone, String verifyCode) {
        SendSmsRequest smsRequest = new SendSmsRequest();
        smsRequest.setPhoneNumbers(phone);
        smsRequest.setSignName("阿里云短信测试");
        smsRequest.setTemplateCode("SMS_154950909");
        smsRequest.setTemplateParam("{\"code\":\""+verifyCode+"\"}");
        try {
            client.sendSms(smsRequest);
        } catch (Exception e) {
            throw new RuntimeException("发送短信失败");
        }
    }
}
